let digits = '23'
let digitsArr = [...digits]
console.log(digitsArr)

let letterMap = {
    "0":[''],
    "1":[''],
    "2":['a', 'b', 'c'],
    "3":['d', 'e', 'f'],
    "4":['g', 'h', 'i'],
    "5":['j', 'k', 'l'],
    "6":['m', 'n', 'o'],
    "7":['p', 'q', 'r', 's'],
    "8":['t', 'u', 'v'],
    "9":['w', 'x', 'y', 'z'],
}

let letterList = []
digitsArr.forEach((item) => {
    let letterArr = letterMap[item]
    console.log(letterArr)
    letterList.push(...letterArr)
})

console.log(letterList)
function isPathOk(path){
    let count = 0
    for(let i = 0; i < path.length; i++){
        if(letterMap[digitsArr[i]].includes(path[i])){
            count++
        }
    }
    if(count == path.length){
        return true
    }else{
        return false
    }
}

let result = []

function backtrack(start, path){
    if(path.length == digitsArr.length && isPathOk(path) && letterList.length != 0){
        let tempPath = [...path]
        let temp = tempPath.join('')
        if(!result.includes(temp)){
            result.push(temp)
        }
        
        return
    }
    for(let i = start; i < letterList.length; i++){
        path.push(letterList[i])
        backtrack(i + 1, path)
        path.pop()
    }
}
backtrack(0, [])
console.log(result)